 Imports MySql.Data.MySqlClient 
 Imports System.Data.OleDb
Imports System.Data.SqlClient
 Imports System .Data .SqlServerCe 
 Imports System.Data.OracleClient 
Imports System.Data
Imports DTO
Public Class PHONGTAMDao
Inherits AbstractDao
 #Region "New" 
 Public Sub New(ByVal connection As KetNoiDto)
 MyBase.New(connection)
 End Sub
 Public Sub New( ByVal IDPHONGTAM As System.Int32, ByVal connection As KetNoiDto)
 MyBase.New("PHONGTAM", "select * from PHONGTAM where IDPHONGTAM=" & IDPHONGTAM & "", connection)
 End Sub
 #End Region 
 Public Sub Them(ByVal Dto As PHONGTAMDto)
 Dim strsql As String
 strsql = "Insert into PHONGTAM(IDPHONG,IDLOPHOC,TUNGAY,DENNGAY,TRANGTHAI,GHICHU) values (?,?,?,?,?,?)
 Moketnoi()
 select case ketnoi.MSsql 
 Case Class_KieuDL.Access
 Dim cmd As New OleDbCommand(strsql, Ket_noi_access)
cmd.Parameters.Add("@IDPHONG", OleDbType.Integer)
cmd.Parameters.Add("@IDLOPHOC", OleDbType.Integer)
cmd.Parameters.Add("@TUNGAY", OleDbType.Date)
cmd.Parameters.Add("@DENNGAY", OleDbType.Date)
cmd.Parameters.Add("@TRANGTHAI", OleDbType.Integer)
cmd.Parameters.Add("@GHICHU", OleDbType.VarWChar)
cmd.Parameters("@IDPHONG").Value = Dto.IDPHONG
cmd.Parameters("@IDLOPHOC").Value = Dto.IDLOPHOC
cmd.Parameters("@TUNGAY").Value = Dto.TUNGAY
cmd.Parameters("@DENNGAY").Value = Dto.DENNGAY
cmd.Parameters("@TRANGTHAI").Value = Dto.TRANGTHAI
cmd.Parameters("@GHICHU").Value = Dto.GHICHU
 cmd.ExecuteNonQuery()
 strsql = "Select @@IDENTITY"
 cmd = New OleDbCommand(strsql, Ket_noi_access)
 Dto.IDPHONGTAM = cmd.ExecuteScalar()
 Case Class_KieuDL.Sql,Class_KieuDL.sqlExpress
 strsql = "Insert into PHONGTAM(IDPHONG,IDLOPHOC,TUNGAY,DENNGAY,TRANGTHAI,GHICHU) values (@IDPHONG,@IDLOPHOC,@TUNGAY,@DENNGAY,@TRANGTHAI,@GHICHU)
 Dim cmd As New sqlCommand(strsql, Ket_noi_sql)
cmd.Parameters.Add("@IDPHONG", SqlDbType.Int)
cmd.Parameters.Add("@IDLOPHOC", SqlDbType.Int)
cmd.Parameters.Add("@TUNGAY", SqlDbType.DateTime)
cmd.Parameters.Add("@DENNGAY", SqlDbType.DateTime)
cmd.Parameters.Add("@TRANGTHAI", SqlDbType.Int)
cmd.Parameters.Add("@GHICHU", SqlDbType.NVarChar)
cmd.Parameters("@IDPHONG").Value = Dto.IDPHONG
cmd.Parameters("@IDLOPHOC").Value = Dto.IDLOPHOC
cmd.Parameters("@TUNGAY").Value = Dto.TUNGAY
cmd.Parameters("@DENNGAY").Value = Dto.DENNGAY
cmd.Parameters("@TRANGTHAI").Value = Dto.TRANGTHAI
cmd.Parameters("@GHICHU").Value = Dto.GHICHU
 cmd.ExecuteNonQuery()
 strsql = "Select @@IDENTITY"
 cmd = New sqlCommand(strsql, Ket_noi_sql)
 Dto.IDPHONGTAM = cmd.ExecuteScalar()
 Case Class_KieuDL.SqlCe
 strsql = "Insert into PHONGTAM(IDPHONG,IDLOPHOC,TUNGAY,DENNGAY,TRANGTHAI,GHICHU) values (@IDPHONG,@IDLOPHOC,@TUNGAY,@DENNGAY,@TRANGTHAI,@GHICHU)
 Dim cmd As New sqlceCommand(strsql, Ket_noi_SqlCe)
cmd.Parameters("@IDPHONG").Value = Dto.IDPHONG
cmd.Parameters("@IDLOPHOC").Value = Dto.IDLOPHOC
cmd.Parameters("@TUNGAY").Value = Dto.TUNGAY
cmd.Parameters("@DENNGAY").Value = Dto.DENNGAY
cmd.Parameters("@TRANGTHAI").Value = Dto.TRANGTHAI
cmd.Parameters("@GHICHU").Value = Dto.GHICHU
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Oracle
 strsql = "Insert into PHONGTAM(IDPHONG,IDLOPHOC,TUNGAY,DENNGAY,TRANGTHAI,GHICHU) values (@IDPHONG,@IDLOPHOC,@TUNGAY,@DENNGAY,@TRANGTHAI,@GHICHU)
 Dim cmd As New OracleCommand(strsql, Ket_noi_Oracle)
cmd.Parameters("@IDPHONG").Value = Dto.IDPHONG
cmd.Parameters("@IDLOPHOC").Value = Dto.IDLOPHOC
cmd.Parameters("@TUNGAY").Value = Dto.TUNGAY
cmd.Parameters("@DENNGAY").Value = Dto.DENNGAY
cmd.Parameters("@TRANGTHAI").Value = Dto.TRANGTHAI
cmd.Parameters("@GHICHU").Value = Dto.GHICHU
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Mysql
 strsql = "Insert into PHONGTAM(IDPHONG,IDLOPHOC,TUNGAY,DENNGAY,TRANGTHAI,GHICHU) values (@IDPHONG,@IDLOPHOC,@TUNGAY,@DENNGAY,@TRANGTHAI,@GHICHU)
 Dim cmd As New MySqlCommand(strsql, Ket_noi_MySql)
cmd.Parameters.Add("@IDPHONG", MySqlDbType.Int32)
cmd.Parameters.Add("@IDLOPHOC", MySqlDbType.Int32)
cmd.Parameters.Add("@TUNGAY",  MySqlDbType.DateTime)
cmd.Parameters.Add("@DENNGAY",  MySqlDbType.DateTime)
cmd.Parameters.Add("@TRANGTHAI", MySqlDbType.Int32)
cmd.Parameters.Add("@GHICHU", MySqlDbType.String)
cmd.Parameters("@IDPHONG").Value = Dto.IDPHONG
cmd.Parameters("@IDLOPHOC").Value = Dto.IDLOPHOC
cmd.Parameters("@TUNGAY").Value = Dto.TUNGAY
cmd.Parameters("@DENNGAY").Value = Dto.DENNGAY
cmd.Parameters("@TRANGTHAI").Value = Dto.TRANGTHAI
cmd.Parameters("@GHICHU").Value = Dto.GHICHU
 cmd.ExecuteNonQuery()
 End Select
 Ngatketnoi()
 End Sub
 Public Sub Xoa( ByVal IDPHONGTAM As System.Int32 )
 Dim strSQL As String
 Moketnoi()
 select case ketnoi.MSsql 
 Case Class_KieuDL.Access
strSQL = "Delete From PHONGTAM Where IDPHONGTAM= ? 
Dim cmd As New OleDbCommand(strSQL, Ket_noi_access)
cmd.Parameters.Add("@IDPHONGTAM",OleDbType.Integer).Value = IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Sql,Class_KieuDL.sqlExpress 
strSQL = "Delete From PHONGTAM Where IDPHONGTAM= @IDPHONGTAM
Dim cmd As New sqlCommand(strSQL, Ket_noi_sql)
cmd.Parameters.Add("@IDPHONGTAM",SqlDbType.Int).value=IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.SqlCe
strSQL = "Delete From PHONGTAM Where IDPHONGTAM=" & IDPHONGTAM & "
 Dim cmd As New SqlCeCommand(strSQL, Ket_noi_SqlCe)
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Oracle
strSQL = "Delete From PHONGTAM Where IDPHONGTAM=" & IDPHONGTAM & "
 Dim cmd As New OracleCommand(strSQL, Ket_noi_Oracle)
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.MySql
strSQL = "Delete From PHONGTAM Where IDPHONGTAM=" & IDPHONGTAM & "
 Dim cmd As New MySqlCommand(strSQL, Ket_noi_MySql)
 cmd.ExecuteNonQuery()
 End Select
 Ngatketnoi()
 End Sub
 Public Sub sua(ByVal dto As PHONGTAMDto)
 Dim strSQL As String
 Moketnoi()
 select case ketnoi.MSsql 
 Case Class_KieuDL.Access
 strSQL = "Update PHONGTAM Set IDPHONG=? ,IDLOPHOC=? ,TUNGAY=? ,DENNGAY=? ,TRANGTHAI=? ,GHICHU= ? where IDPHONGTAM= ? "
 Dim cmd As New OleDbCommand(strSQL, Ket_noi_access)
cmd.Parameters.Add("@IDPHONG", OleDbType.Integer)
cmd.Parameters.Add("@IDLOPHOC", OleDbType.Integer)
cmd.Parameters.Add("@TUNGAY", OleDbType.Date)
cmd.Parameters.Add("@DENNGAY", OleDbType.Date)
cmd.Parameters.Add("@TRANGTHAI", OleDbType.Integer)
cmd.Parameters.Add("@GHICHU", OleDbType.VarWChar)
cmd.Parameters.Add("@IDPHONGTAM", OleDbType.Integer)
cmd.Parameters("@IDPHONG").Value = dto.IDPHONG
cmd.Parameters("@IDLOPHOC").Value = dto.IDLOPHOC
cmd.Parameters("@TUNGAY").Value = dto.TUNGAY
cmd.Parameters("@DENNGAY").Value = dto.DENNGAY
cmd.Parameters("@TRANGTHAI").Value = dto.TRANGTHAI
cmd.Parameters("@GHICHU").Value = dto.GHICHU
cmd.Parameters("@IDPHONGTAM").Value = dto.IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Sql,Class_KieuDL.sqlExpress 
 strSQL = "Update PHONGTAM Set IDPHONG= @IDPHONG , IDLOPHOC= @IDLOPHOC , TUNGAY= @TUNGAY , DENNGAY= @DENNGAY , TRANGTHAI= @TRANGTHAI , GHICHU= @GHICHU where IDPHONGTAM= @IDPHONGTAM"
 Dim cmd As New sqlCommand(strSQL, Ket_noi_sql)
cmd.Parameters.Add("@IDPHONG", SqlDbType.Int)
cmd.Parameters.Add("@IDLOPHOC", SqlDbType.Int)
cmd.Parameters.Add("@TUNGAY", SqlDbType.DateTime)
cmd.Parameters.Add("@DENNGAY", SqlDbType.DateTime)
cmd.Parameters.Add("@TRANGTHAI", SqlDbType.Int)
cmd.Parameters.Add("@GHICHU", SqlDbType.NVarChar)
cmd.Parameters.Add("@IDPHONGTAM", SqlDbType.Int)
cmd.Parameters("@IDPHONG").Value = dto.IDPHONG
cmd.Parameters("@IDLOPHOC").Value = dto.IDLOPHOC
cmd.Parameters("@TUNGAY").Value = dto.TUNGAY
cmd.Parameters("@DENNGAY").Value = dto.DENNGAY
cmd.Parameters("@TRANGTHAI").Value = dto.TRANGTHAI
cmd.Parameters("@GHICHU").Value = dto.GHICHU
cmd.Parameters("@IDPHONGTAM").Value = dto.IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.SqlCe
 strSQL = "Update PHONGTAM Set IDPHONG= @IDPHONG , IDLOPHOC= @IDLOPHOC , TUNGAY= @TUNGAY , DENNGAY= @DENNGAY , TRANGTHAI= @TRANGTHAI , GHICHU= @GHICHU where IDPHONGTAM= @IDPHONGTAM"
 Dim cmd As New SqlCeCommand(strSQL, Ket_noi_SqlCe)
cmd.Parameters("@IDPHONG").Value = dto.IDPHONG
cmd.Parameters("@IDLOPHOC").Value = dto.IDLOPHOC
cmd.Parameters("@TUNGAY").Value = dto.TUNGAY
cmd.Parameters("@DENNGAY").Value = dto.DENNGAY
cmd.Parameters("@TRANGTHAI").Value = dto.TRANGTHAI
cmd.Parameters("@GHICHU").Value = dto.GHICHU
cmd.Parameters("@IDPHONGTAM").Value = dto.IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Oracle
 strSQL = "Update PHONGTAM Set IDPHONG= @IDPHONG , IDLOPHOC= @IDLOPHOC , TUNGAY= @TUNGAY , DENNGAY= @DENNGAY , TRANGTHAI= @TRANGTHAI , GHICHU= @GHICHU where IDPHONGTAM= @IDPHONGTAM"
 Dim cmd As New OracleCommand(strSQL, Ket_noi_Oracle)
cmd.Parameters("@IDPHONG").Value = dto.IDPHONG
cmd.Parameters("@IDLOPHOC").Value = dto.IDLOPHOC
cmd.Parameters("@TUNGAY").Value = dto.TUNGAY
cmd.Parameters("@DENNGAY").Value = dto.DENNGAY
cmd.Parameters("@TRANGTHAI").Value = dto.TRANGTHAI
cmd.Parameters("@GHICHU").Value = dto.GHICHU
cmd.Parameters("@IDPHONGTAM").Value = dto.IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.MySql
 strSQL = "Update PHONGTAM Set IDPHONG= @IDPHONG , IDLOPHOC= @IDLOPHOC , TUNGAY= @TUNGAY , DENNGAY= @DENNGAY , TRANGTHAI= @TRANGTHAI , GHICHU= @GHICHU where IDPHONGTAM= @IDPHONGTAM"
 Dim cmd As New MySqlCommand(strSQL, Ket_noi_MySql)
cmd.Parameters.Add("@IDPHONG", MySqlDbType.Int32)
cmd.Parameters.Add("@IDLOPHOC", MySqlDbType.Int32)
cmd.Parameters.Add("@TUNGAY",  MySqlDbType.DateTime)
cmd.Parameters.Add("@DENNGAY",  MySqlDbType.DateTime)
cmd.Parameters.Add("@TRANGTHAI", MySqlDbType.Int32)
cmd.Parameters.Add("@GHICHU", MySqlDbType.String)
cmd.Parameters.Add("@IDPHONGTAM", MySqlDbType.Int32)
cmd.Parameters("@IDPHONG").Value = dto.IDPHONG
cmd.Parameters("@IDLOPHOC").Value = dto.IDLOPHOC
cmd.Parameters("@TUNGAY").Value = dto.TUNGAY
cmd.Parameters("@DENNGAY").Value = dto.DENNGAY
cmd.Parameters("@TRANGTHAI").Value = dto.TRANGTHAI
cmd.Parameters("@GHICHU").Value = dto.GHICHU
cmd.Parameters("@IDPHONGTAM").Value = dto.IDPHONGTAM
 cmd.ExecuteNonQuery()
 End Select
 Ngatketnoi()
 End Sub
 Public Sub SuaIDPHONG( ByVal IDPHONG as System.Int32, ByVal IDPHONGTAM As System.Int32 )
 Dim strSQL As String
 Moketnoi()
 select case ketnoi.MSsql 
 Case Class_KieuDL.Access
 strSQL = "Update PHONGTAM Set IDPHONG = ?  where IDPHONGTAM= ? "
 Dim cmd As New OleDbCommand(strSQL, Ket_noi_access)
 cmd.Parameters.Add("@IDPHONG", OleDbType.Integer)
 cmd.Parameters.Add("@IDPHONGTAM", OleDbType.Integer)
 cmd.Parameters("@IDPHONG").Value =  IDPHONG
cmd.Parameters("@IDPHONGTAM").Value =  IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Sql,Class_KieuDL.sqlExpress 
 strSQL = "Update PHONGTAM Set IDPHONG = @IDPHONG  where IDPHONGTAM= @IDPHONGTAM"
 Dim cmd As New sqlCommand(strSQL, Ket_noi_sql)
 cmd.Parameters.Add("@IDPHONG", SqlDbType.Int)
 cmd.Parameters.Add("@IDPHONGTAM", SqlDbType.Int)
 cmd.Parameters("@IDPHONG").Value =  IDPHONG
cmd.Parameters("@IDPHONGTAM").Value =  IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.SqlCe
 strSQL = "Update PHONGTAM Set IDPHONG =" & IDPHONG & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New SqlCeCommand(strSQL, Ket_noi_SqlCe)
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Oracle
 strSQL = "Update PHONGTAM Set IDPHONG =" & IDPHONG & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New OracleCommand(strSQL, Ket_noi_Oracle)
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.MySql
 strSQL = "Update PHONGTAM Set IDPHONG =" & IDPHONG & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New MySqlCommand(strSQL, Ket_noi_MySql)
 cmd.ExecuteNonQuery()
 End Select 
 Ngatketnoi()
 End Sub
 Public Sub SuaIDLOPHOC( ByVal IDLOPHOC as System.Int32, ByVal IDPHONGTAM As System.Int32 )
 Dim strSQL As String
 Moketnoi()
 select case ketnoi.MSsql 
 Case Class_KieuDL.Access
 strSQL = "Update PHONGTAM Set IDLOPHOC = ?  where IDPHONGTAM= ? "
 Dim cmd As New OleDbCommand(strSQL, Ket_noi_access)
 cmd.Parameters.Add("@IDLOPHOC", OleDbType.Integer)
 cmd.Parameters.Add("@IDPHONGTAM", OleDbType.Integer)
 cmd.Parameters("@IDLOPHOC").Value =  IDLOPHOC
cmd.Parameters("@IDPHONGTAM").Value =  IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Sql,Class_KieuDL.sqlExpress 
 strSQL = "Update PHONGTAM Set IDLOPHOC = @IDLOPHOC  where IDPHONGTAM= @IDPHONGTAM"
 Dim cmd As New sqlCommand(strSQL, Ket_noi_sql)
 cmd.Parameters.Add("@IDLOPHOC", SqlDbType.Int)
 cmd.Parameters.Add("@IDPHONGTAM", SqlDbType.Int)
 cmd.Parameters("@IDLOPHOC").Value =  IDLOPHOC
cmd.Parameters("@IDPHONGTAM").Value =  IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.SqlCe
 strSQL = "Update PHONGTAM Set IDLOPHOC =" & IDLOPHOC & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New SqlCeCommand(strSQL, Ket_noi_SqlCe)
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Oracle
 strSQL = "Update PHONGTAM Set IDLOPHOC =" & IDLOPHOC & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New OracleCommand(strSQL, Ket_noi_Oracle)
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.MySql
 strSQL = "Update PHONGTAM Set IDLOPHOC =" & IDLOPHOC & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New MySqlCommand(strSQL, Ket_noi_MySql)
 cmd.ExecuteNonQuery()
 End Select 
 Ngatketnoi()
 End Sub
 Public Sub SuaTUNGAY( ByVal TUNGAY as System.DateTime, ByVal IDPHONGTAM As System.Int32 )
 Dim strSQL As String
 Moketnoi()
 select case ketnoi.MSsql 
 Case Class_KieuDL.Access
 strSQL = "Update PHONGTAM Set TUNGAY = ?  where IDPHONGTAM= ? "
 Dim cmd As New OleDbCommand(strSQL, Ket_noi_access)
 cmd.Parameters.Add("@TUNGAY", OleDbType.Date)
 cmd.Parameters.Add("@IDPHONGTAM", OleDbType.Integer)
 cmd.Parameters("@TUNGAY").Value =  TUNGAY
cmd.Parameters("@IDPHONGTAM").Value =  IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Sql,Class_KieuDL.sqlExpress 
 strSQL = "Update PHONGTAM Set TUNGAY = @TUNGAY  where IDPHONGTAM= @IDPHONGTAM"
 Dim cmd As New sqlCommand(strSQL, Ket_noi_sql)
 cmd.Parameters.Add("@TUNGAY", SqlDbType.DateTime)
 cmd.Parameters.Add("@IDPHONGTAM", SqlDbType.Int)
 cmd.Parameters("@TUNGAY").Value =  TUNGAY
cmd.Parameters("@IDPHONGTAM").Value =  IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.SqlCe
 strSQL = "Update PHONGTAM Set TUNGAY =" & TUNGAY & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New SqlCeCommand(strSQL, Ket_noi_SqlCe)
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Oracle
 strSQL = "Update PHONGTAM Set TUNGAY =" & TUNGAY & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New OracleCommand(strSQL, Ket_noi_Oracle)
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.MySql
 strSQL = "Update PHONGTAM Set TUNGAY =" & TUNGAY & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New MySqlCommand(strSQL, Ket_noi_MySql)
 cmd.ExecuteNonQuery()
 End Select 
 Ngatketnoi()
 End Sub
 Public Sub SuaDENNGAY( ByVal DENNGAY as System.DateTime, ByVal IDPHONGTAM As System.Int32 )
 Dim strSQL As String
 Moketnoi()
 select case ketnoi.MSsql 
 Case Class_KieuDL.Access
 strSQL = "Update PHONGTAM Set DENNGAY = ?  where IDPHONGTAM= ? "
 Dim cmd As New OleDbCommand(strSQL, Ket_noi_access)
 cmd.Parameters.Add("@DENNGAY", OleDbType.Date)
 cmd.Parameters.Add("@IDPHONGTAM", OleDbType.Integer)
 cmd.Parameters("@DENNGAY").Value =  DENNGAY
cmd.Parameters("@IDPHONGTAM").Value =  IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Sql,Class_KieuDL.sqlExpress 
 strSQL = "Update PHONGTAM Set DENNGAY = @DENNGAY  where IDPHONGTAM= @IDPHONGTAM"
 Dim cmd As New sqlCommand(strSQL, Ket_noi_sql)
 cmd.Parameters.Add("@DENNGAY", SqlDbType.DateTime)
 cmd.Parameters.Add("@IDPHONGTAM", SqlDbType.Int)
 cmd.Parameters("@DENNGAY").Value =  DENNGAY
cmd.Parameters("@IDPHONGTAM").Value =  IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.SqlCe
 strSQL = "Update PHONGTAM Set DENNGAY =" & DENNGAY & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New SqlCeCommand(strSQL, Ket_noi_SqlCe)
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Oracle
 strSQL = "Update PHONGTAM Set DENNGAY =" & DENNGAY & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New OracleCommand(strSQL, Ket_noi_Oracle)
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.MySql
 strSQL = "Update PHONGTAM Set DENNGAY =" & DENNGAY & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New MySqlCommand(strSQL, Ket_noi_MySql)
 cmd.ExecuteNonQuery()
 End Select 
 Ngatketnoi()
 End Sub
 Public Sub SuaTRANGTHAI( ByVal TRANGTHAI as System.Int32, ByVal IDPHONGTAM As System.Int32 )
 Dim strSQL As String
 Moketnoi()
 select case ketnoi.MSsql 
 Case Class_KieuDL.Access
 strSQL = "Update PHONGTAM Set TRANGTHAI = ?  where IDPHONGTAM= ? "
 Dim cmd As New OleDbCommand(strSQL, Ket_noi_access)
 cmd.Parameters.Add("@TRANGTHAI", OleDbType.Integer)
 cmd.Parameters.Add("@IDPHONGTAM", OleDbType.Integer)
 cmd.Parameters("@TRANGTHAI").Value =  TRANGTHAI
cmd.Parameters("@IDPHONGTAM").Value =  IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Sql,Class_KieuDL.sqlExpress 
 strSQL = "Update PHONGTAM Set TRANGTHAI = @TRANGTHAI  where IDPHONGTAM= @IDPHONGTAM"
 Dim cmd As New sqlCommand(strSQL, Ket_noi_sql)
 cmd.Parameters.Add("@TRANGTHAI", SqlDbType.Int)
 cmd.Parameters.Add("@IDPHONGTAM", SqlDbType.Int)
 cmd.Parameters("@TRANGTHAI").Value =  TRANGTHAI
cmd.Parameters("@IDPHONGTAM").Value =  IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.SqlCe
 strSQL = "Update PHONGTAM Set TRANGTHAI =" & TRANGTHAI & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New SqlCeCommand(strSQL, Ket_noi_SqlCe)
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Oracle
 strSQL = "Update PHONGTAM Set TRANGTHAI =" & TRANGTHAI & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New OracleCommand(strSQL, Ket_noi_Oracle)
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.MySql
 strSQL = "Update PHONGTAM Set TRANGTHAI =" & TRANGTHAI & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New MySqlCommand(strSQL, Ket_noi_MySql)
 cmd.ExecuteNonQuery()
 End Select 
 Ngatketnoi()
 End Sub
 Public Sub SuaGHICHU( ByVal GHICHU as System.String, ByVal IDPHONGTAM As System.Int32 )
 Dim strSQL As String
 Moketnoi()
 select case ketnoi.MSsql 
 Case Class_KieuDL.Access
 strSQL = "Update PHONGTAM Set GHICHU = ?  where IDPHONGTAM= ? "
 Dim cmd As New OleDbCommand(strSQL, Ket_noi_access)
 cmd.Parameters.Add("@GHICHU", OleDbType.VarWChar)
 cmd.Parameters.Add("@IDPHONGTAM", OleDbType.Integer)
 cmd.Parameters("@GHICHU").Value =  GHICHU
cmd.Parameters("@IDPHONGTAM").Value =  IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Sql,Class_KieuDL.sqlExpress 
 strSQL = "Update PHONGTAM Set GHICHU = @GHICHU  where IDPHONGTAM= @IDPHONGTAM"
 Dim cmd As New sqlCommand(strSQL, Ket_noi_sql)
 cmd.Parameters.Add("@GHICHU", SqlDbType.NVarChar)
 cmd.Parameters.Add("@IDPHONGTAM", SqlDbType.Int)
 cmd.Parameters("@GHICHU").Value =  GHICHU
cmd.Parameters("@IDPHONGTAM").Value =  IDPHONGTAM
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.SqlCe
 strSQL = "Update PHONGTAM Set GHICHU =" & GHICHU & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New SqlCeCommand(strSQL, Ket_noi_SqlCe)
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.Oracle
 strSQL = "Update PHONGTAM Set GHICHU =" & GHICHU & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New OracleCommand(strSQL, Ket_noi_Oracle)
 cmd.ExecuteNonQuery()
 Case Class_KieuDL.MySql
 strSQL = "Update PHONGTAM Set GHICHU =" & GHICHU & "  where IDPHONGTAM=" & IDPHONGTAM & ""
 Dim cmd As New MySqlCommand(strSQL, Ket_noi_MySql)
 cmd.ExecuteNonQuery()
 End Select 
 Ngatketnoi()
 End Sub
 Public Sub layBang()
 Chuoi_SQL = " Select * from PHONGTAM
 Doc_bang()
 End Sub
 Public Sub layBangTheoIDPHONGTAM(ByVal ARRAY1 As ArrayList)
 Dim DK As String = ""
 If ARRAY1.Count > 0 Then
 For I As Integer = 0 To ARRAY1.Count - 1
 DK = DK & IIf(DK <> "", " OR ", "") & "IDPHONGTAM=" & ARRAY1.Item(i) & ""
 Next
 End If
 If DK <> "" Then DK = " WHERE " & DK 
 Chuoi_SQL = " Select * from PHONGTAM" & DK
 Doc_bang()
 End Sub
 Public Sub layBangTheoIDPHONGTAM(ByVal IDPHONGTAM As System.Int32 )
 Chuoi_SQL = " Select * from PHONGTAM where  IDPHONGTAM = " & IDPHONGTAM & ""
 Doc_bang()
 End Sub
 Public Sub XOABangTheoIDPHONGTAM(ByVal IDPHONGTAM As System.Int32)
 Dim strsql As String
 strSQL = "Delete From PHONGTAM Where IDPHONGTAM=" & IDPHONGTAM & ""
 Thuc_hien_lenh(strsql)
 End Sub
 Public Sub layBangTheoIDPHONG(ByVal ARRAY1 As ArrayList)
 Dim DK As String = ""
 If ARRAY1.Count > 0 Then
 For I As Integer = 0 To ARRAY1.Count - 1
 DK = DK & IIf(DK <> "", " OR ", "") & "IDPHONG=" & ARRAY1.Item(i) & ""
 Next
 End If
 If DK <> "" Then DK = " WHERE " & DK 
 Chuoi_SQL = " Select * from PHONGTAM" & DK
 Doc_bang()
 End Sub
 Public Sub layBangTheoIDPHONG(ByVal IDPHONG As System.Int32 )
 Chuoi_SQL = " Select * from PHONGTAM where  IDPHONG = " & IDPHONG & ""
 Doc_bang()
 End Sub
 Public Sub XOABangTheoIDPHONG(ByVal IDPHONG As System.Int32)
 Dim strsql As String
 strSQL = "Delete From PHONGTAM Where IDPHONG=" & IDPHONG & ""
 Thuc_hien_lenh(strsql)
 End Sub
 Public Sub layBangTheoIDLOPHOC(ByVal ARRAY1 As ArrayList)
 Dim DK As String = ""
 If ARRAY1.Count > 0 Then
 For I As Integer = 0 To ARRAY1.Count - 1
 DK = DK & IIf(DK <> "", " OR ", "") & "IDLOPHOC=" & ARRAY1.Item(i) & ""
 Next
 End If
 If DK <> "" Then DK = " WHERE " & DK 
 Chuoi_SQL = " Select * from PHONGTAM" & DK
 Doc_bang()
 End Sub
 Public Sub layBangTheoIDLOPHOC(ByVal IDLOPHOC As System.Int32 )
 Chuoi_SQL = " Select * from PHONGTAM where  IDLOPHOC = " & IDLOPHOC & ""
 Doc_bang()
 End Sub
 Public Sub XOABangTheoIDLOPHOC(ByVal IDLOPHOC As System.Int32)
 Dim strsql As String
 strSQL = "Delete From PHONGTAM Where IDLOPHOC=" & IDLOPHOC & ""
 Thuc_hien_lenh(strsql)
 End Sub
 Public Sub layBangTheoTUNGAY(ByVal ARRAY1 As ArrayList)
 Dim DK As String = ""
 If ARRAY1.Count > 0 Then
 For I As Integer = 0 To ARRAY1.Count - 1
 DK = DK & IIf(DK <> "", " OR ", "") & "TUNGAY='" & ARRAY1.Item(i) & "'"
 Next
 End If
 If DK <> "" Then DK = " WHERE " & DK 
 Chuoi_SQL = " Select * from PHONGTAM" & DK
 Doc_bang()
 End Sub
 Public Sub layBangTheoTUNGAY(ByVal TUNGAY As System.DateTime )
 Chuoi_SQL = " Select * from PHONGTAM where  TUNGAY = @Ngay
 Doc_bang_Dk_ngay(TUNGAY)
 End Sub
 Public Sub layBangTheoTUNGAY(ByVal TUNGAY1 As System.DateTime,ByVal TUNGAY2 As System.DateTime )
 Chuoi_SQL = " Select * from PHONGTAM where  TUNGAY >= @Ngay and TUNGAY <= @denNgay ORDER BY TUNGAY
 Doc_bang_Dk_ngay(TUNGAY1,TUNGAY2)
 End Sub
 Public Sub XOABangTheoTUNGAY(ByVal TUNGAY As System.DateTime)
 Dim strsql As String
 strSQL = "Delete From PHONGTAM Where TUNGAY='" & TUNGAY & "'"
 Thuc_hien_lenh(strsql)
 End Sub
 Public Sub layBangTheoDENNGAY(ByVal ARRAY1 As ArrayList)
 Dim DK As String = ""
 If ARRAY1.Count > 0 Then
 For I As Integer = 0 To ARRAY1.Count - 1
 DK = DK & IIf(DK <> "", " OR ", "") & "DENNGAY='" & ARRAY1.Item(i) & "'"
 Next
 End If
 If DK <> "" Then DK = " WHERE " & DK 
 Chuoi_SQL = " Select * from PHONGTAM" & DK
 Doc_bang()
 End Sub
 Public Sub layBangTheoDENNGAY(ByVal DENNGAY As System.DateTime )
 Chuoi_SQL = " Select * from PHONGTAM where  DENNGAY = @Ngay
 Doc_bang_Dk_ngay(DENNGAY)
 End Sub
 Public Sub layBangTheoDENNGAY(ByVal DENNGAY1 As System.DateTime,ByVal DENNGAY2 As System.DateTime )
 Chuoi_SQL = " Select * from PHONGTAM where  DENNGAY >= @Ngay and DENNGAY <= @denNgay ORDER BY DENNGAY
 Doc_bang_Dk_ngay(DENNGAY1,DENNGAY2)
 End Sub
 Public Sub XOABangTheoDENNGAY(ByVal DENNGAY As System.DateTime)
 Dim strsql As String
 strSQL = "Delete From PHONGTAM Where DENNGAY='" & DENNGAY & "'"
 Thuc_hien_lenh(strsql)
 End Sub
 Public Sub layBangTheoTRANGTHAI(ByVal ARRAY1 As ArrayList)
 Dim DK As String = ""
 If ARRAY1.Count > 0 Then
 For I As Integer = 0 To ARRAY1.Count - 1
 DK = DK & IIf(DK <> "", " OR ", "") & "TRANGTHAI=" & ARRAY1.Item(i) & ""
 Next
 End If
 If DK <> "" Then DK = " WHERE " & DK 
 Chuoi_SQL = " Select * from PHONGTAM" & DK
 Doc_bang()
 End Sub
 Public Sub layBangTheoTRANGTHAI(ByVal TRANGTHAI As System.Int32 )
 Chuoi_SQL = " Select * from PHONGTAM where  TRANGTHAI = " & TRANGTHAI & ""
 Doc_bang()
 End Sub
 Public Sub XOABangTheoTRANGTHAI(ByVal TRANGTHAI As System.Int32)
 Dim strsql As String
 strSQL = "Delete From PHONGTAM Where TRANGTHAI=" & TRANGTHAI & ""
 Thuc_hien_lenh(strsql)
 End Sub
 Public Sub layBangTheoGHICHU(ByVal ARRAY1 As ArrayList)
 Dim DK As String = ""
 If ARRAY1.Count > 0 Then
 For I As Integer = 0 To ARRAY1.Count - 1
 DK = DK & IIf(DK <> "", " OR ", "") & "GHICHU='" & ARRAY1.Item(i) & "'"
 Next
 End If
 If DK <> "" Then DK = " WHERE " & DK 
 Chuoi_SQL = " Select * from PHONGTAM" & DK
 Doc_bang()
 End Sub
 Public Sub layBangTheoGHICHU_like (ByVal GHICHU As System.String )
 Chuoi_SQL = " Select * from PHONGTAM where  GHICHU  like '%" & GHICHU & "%'"
 Doc_bang()
 End Sub
 Public Sub layBangTheoGHICHU(ByVal GHICHU As System.String )
 Chuoi_SQL = " Select * from PHONGTAM where  GHICHU = '" & GHICHU & "'"
 Doc_bang()
 End Sub
 Public Sub XOABangTheoGHICHU(ByVal GHICHU As System.String)
 Dim strsql As String
 strSQL = "Delete From PHONGTAM Where GHICHU='" & GHICHU & "'"
 Thuc_hien_lenh(strsql)
 End Sub
 Public Sub layBangNhieuTable
 Chuoi_SQL = " Select IDPHONGTAM ,IDPHONG ,IDLOPHOC ,TUNGAY ,DENNGAY ,TRANGTHAI ,GHICHU  from PHONGTAM"
 Doc_bang()
 End sub
Public Sub TaoTable()
Dim strsql As String
strsql = ""
Select Case ketnoi.MsSql
Case Class_KieuDL.Access 
Case Class_KieuDL.Sql, Class_KieuDL.sqlExpress
strsql = ""
Case Class_KieuDL.SqlCe
strsql = ""
Case Class_KieuDL.Oracle
strsql = ""
Case else 
strsql = ""
End Select
Thuc_hien_lenh(strsql)
End Sub
 End Class

